package com.obtk.byproperty.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@RestController
public class IndexController {
    @RequestMapping("index")
    public String show(HttpServletRequest request){
        System.out.println(request.getAttribute("image"));
        //获取到我们当前应用的ip和端口
        String localAddr = request.getRemoteHost() ;
        int serverPort = request.getServerPort();
        //因为转发过来之前我们此图片就已经被我们的过滤器映射到我们的SpringBoot项目下的images文件中了(此过滤器为我们生成的虚拟文件夹)
        String  newUrl="http://"+localAddr +":"+ serverPort+"/images/"+request.getAttribute("image");
        System.out.println(newUrl);
        return newUrl;
    }}
